Pulling user updated HTML table data into Python

by: glennf, 7 years ago


Can anyone provide some guidance on how to get updated table data back into Python from an HTML page I rendered using jinja. I tried BeautifulSoup but didn't have success getting it to look at the page that I received the POST from.

This is the python code (imports and non related code not included)

                url = "plan_update.html"
                page = open(url)
                soup = BeautifulSoup((page.read()), "lxml")
                plantable = soup.findAll("table",class_="plantable")  
                for row in plantable.findAll("tr"):  
                    for cells in row.findAll("td"):
                        if (cells[9].find(text=True)) != 0:
                            Time = cells[5].find(text=True)
                            Quantity = cells[6].find(text=True)
                            Reps = cells[7].find(text=True)
                            Rest = cells[8].find(text=True)
                            Seq = cells[9].find(text=True)


and here is the HTML


<table id="woTable" style="width:100%" class="plantable">
<tr>
{% for planworow in planwodata %}
<td value="{{planworow.workout_name}}">{{planworow.workout_name}}</td>
<td id="linkselect" name="linkselect" value="{{planworow.workout_link}}" onclick="showlink">{{planworow.workout_link}}</td>
<td value="{{planworow.workout_owner_cat}}">{{planworow.workout_owner_cat}}</td>
<td value="{{planworow.workout_owner_sub_cat}}">{{planworow.workout_owner_sub_cat}}</td>
<td contenteditable='true' value="{{planworow.workout_time_allowed_seconds}}">{{planworow.workout_time_allowed_seconds}}</td>
<td contenteditable='true' value="{{planworow.workout_quantity}}">{{planworow.workout_quantity}}</td>
<td contenteditable='true' value="{{planworow.workout_reps}}">{{planworow.workout_reps}}</td>
<td contenteditable='true' value="{{planworow.workout_rest_time_allowed_seconds}}">{{planworow.workout_rest_time_allowed_seconds}}</td>
<td contenteditable='true' value="{{planworow.workout_owner_seq}}">{{planworow.workout_owner_seq}}</td>
{% endfor %}
</tr>


I get the following error which I believe is related to the fact that nothing is brought back by BeautifulSoup.

'ResultSet' object has no attribute 'findAll'

Thank you for any help you can provide.



You must be logged in to post. Please login or register an account.



Hmm, which findall fails? tr or td?

-Harrison 7 years ago

You must be logged in to post. Please login or register an account.


I believe TR - I am wondering if BeautifulSoup sees the "local" page that I generated - all examples I find show it looking at a outside page, that is, one that I did not generate.  I am trying to read user updated information updated from a page that is created within this application and dynamic for that POST event.  I am wondering if I've taken the wrong path and should be using JQuery, JSON and maybe AJAX to get this data instead. I am a bit stuck trying that method as well - if that sounds like a better route can you recommend a tutorial, I did a search of your site but couldn't locate a solution to try.  THANK YOU for the help!

-glennf 7 years ago

You must be logged in to post. Please login or register an account.